package com.simpletour.qa.user.service.impl;

import com.simpletour.qa.common.entity.User;
import com.simpletour.qa.user.biz.UserBiz;
import com.simpletour.qa.user.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author zhaohw
 * @date 2018-06-21 17:21
 */
@Controller
@RequestMapping(value = "rpc/user")
public class UserServiceImpl implements IUserService {

    @Resource
    private UserBiz userBiz;

    @RequestMapping(value = "/username/{username}",method = RequestMethod.GET)
    @ResponseBody
    @Override
    public User findUserByUsername(@PathVariable String username) {
        return userBiz.findUserByUsername(username);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    @Override
    public User findUserByUserId(@PathVariable Integer id) {
        Optional<User> user = userBiz.findById(id);
        if(user.isPresent()){
            user.get().setPassword(null);
            return user.get();
        }
        return null;
    }
}
